package com.wthink.newMain.settings.update.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wthink.hzgj.BusApplication
import com.wthink.hzgj.data.Result
import com.wthink.hzgj.data.domain.VersionInfos
import com.wthink.hzgj.service.DevService
import com.wthink.hzgj.util.toast
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class UpdateFixViewmodel : ViewModel(){

    val devVersion = MutableLiveData<VersionInfos>()

    fun start(){
        viewModelScope.launch(Dispatchers.IO) {
            val ret = DevService.queryDevVersion()
            if (ret is Result.Success) {
                devVersion.postValue(ret.data)
            }
        }
    }

    fun update(type: String) {
        viewModelScope.launch(Dispatchers.IO) {
            val ret = DevService.reqUpdate(type)
            if (ret is Result.Success) {
                withContext(Dispatchers.Main) {
                    toast(BusApplication.busContext,"发送升级请求成功")
                }

            }
        }

    }
}